package com.example.demo.controller;

import com.example.demo.common.Result;
import com.example.demo.dto.DriverCUDTO;
import com.example.demo.dto.DriverGetDTO;
import com.example.demo.service.DriverService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("api/v1/driver")
public class DriverController {
    @Autowired
    private DriverService driverService;

    @GetMapping
    public Result getDrivers(DriverGetDTO driverGetDTO){
        return driverService.searchDriver(driverGetDTO);
    }

    @PostMapping
    public Result addDriver(@RequestBody DriverCUDTO driverCreateDTO){
        return driverService.addDriver(driverCreateDTO);
    }

    @PutMapping
    public Result updateDriver(@RequestBody DriverCUDTO driverCreateDTO){
        return driverService.updateDriver(driverCreateDTO);
    }

    @DeleteMapping("/{id}")
    public Result deleteDriver(@PathVariable("id") Integer id) {
        return driverService.deleteDriver(id);
    }

    @DeleteMapping("/batDelete")
    public Result deleteBat(@RequestBody String[] ids){
        return driverService.batDelete(ids);
    }
}
